package com.xyw.code.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xyw.code.entity.SysMenu;
import com.xyw.code.entity.SysRole;
import org.apache.ibatis.annotations.Select;

import javax.management.relation.Role;
import java.util.List;

/**
 * <p>
 * 系统角色表 Mapper 接口
 * </p>
 *
 * @author xuyiwei
 * @since 2019-07-30
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 通过用户ID，查询角色信息
     *
     * @param userId
     * @return
     */
    @Select("SELECT r.* FROM sys_role r, sys_user_role ur WHERE r.id = ur.role_id AND r.status = 1 and  ur.user_id IN (#{userId})")
    List<SysRole> listRolesByUserId(Integer userId);

    /**
     * 根据角色得到菜单
     * @param roleId
     * @return
     */
    @Select("select m.id,m.name,m.type,m.parent_id,m.sort,m.perms from sys_menu m, sys_role_menu rm where rm.role_id = #{roleId} and m.id = rm.menu_id")
    List<SysMenu> findMenuListByRoleId(int roleId);
}
